import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getwidget/getwidget.dart';
import 'package:ichinesereader/controller/books.dart';
import 'package:ichinesereader/pages/teacher/homeworkStepper.dart';
import 'package:ichinesereader/widgets/dialogs/simpleAlertDialog.dart';

import '../../themes/appTheme.dart';

class FloatingActionButtonCreateAssignment extends StatelessWidget {
  FloatingActionButtonCreateAssignment({
    Key? key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    BooksController _controller = Get.find();
    return Column(
      mainAxisAlignment: MainAxisAlignment.end,
      children: <Widget>[
        SizedBox(
          width: 45.0,
          height: 45.0,
          child: FloatingActionButton(
            backgroundColor: Get.isDarkMode
                ? Theme.of(context).primaryColorDark
                : AppTheme.colors.pinkBtn,
            foregroundColor:
                Get.isDarkMode ? Colors.black : AppTheme.colors.lightPink,
            heroTag: Text('createassignment0000'),
            tooltip: 'Create Homework'.tr,
            onPressed: () {
              if (_controller.selectedFavoriteReadingBookItems.length > 0) {
                Get.to(() => HomeworkSteps(
                      isNew: true,
                      books: _controller.selectedFavoriteReadingBookItems,
                    ));
              } else {
                showGeneralDialog(
                    context: context,
                    transitionDuration: Duration(milliseconds: 400),
                    pageBuilder: (bc, ania, anis) {
                      return SimpleAlertDialog(
                          title: 'No Book'.tr,
                          message:
                              'Please select at least one book to ASSIGN!'.tr);
                    });
              }
            },
            child: Obx(() {
              int? num;
              if (_controller.selectedFavoriteReadingBookItems.length > 0)
                num = _controller.selectedFavoriteReadingBookItems.length;

              if (num != null && num > 0) {
                return GFBadge(
                  child: Text('+$num'),
                  size: 32,
                );
              } else {
                return Icon(
                  Icons.assignment,
                  color:
                      Get.isDarkMode ? Colors.black : AppTheme.colors.lightPink,
                  size: 24,
                );
              }
            }),
            elevation: 12,
            //splashColor: Colors.grey,
          ),
        ),
      ],
    );
  }
}
